#!/usr/bin/tcsh -f
set USAGE="Usage: epp NSTEPS XYZ_FILE [-gamma gamma] [-drmax drmax]"

if ($# < 2)then
    echo $USAGE
    exit
endif

set help_steps="NSTEPS (integer) is a number of relaxation steps. Must set, no default."
set XGAMMA=0.5
set help_gamma="GAMMA (real): in each step, atom i is moved by gamma * dR_i, where dR_i is calculated from the assumption of proximity of a quadratic minimum. Default: GAMMA=$XGAMMA"
set DRMAX=0.30
set help_drmax="DRMAX (real): put the upper bound on atomic displacement in one step, for pathological cases. Default: DRMAX=$DRMAX"

set SRCDIR="$DECAHOME/SRC"
set EXEC="$DECAHOME/bin/epp_"

############################## start ######################################
if($1 == "-h" )then
    echo $USAGE
    echo "------------------------------------------------------------------------"
    shift
    echo "$help_steps\n$help_gamma\n$help_drmax" | fold -s -w 70
    exit
endif

#first argument is number of steps
set NSTEPS=$1
shift
#second argument is tiling/config
if ( -e $1 ) then
    set FNAME=$1
    shift
else
    echo "XYZ file $1 does not exist."
    echo $USAGE;
    exit
endif

while ( "$*" != "" )
    switch ( $1 )
	case -gamma:
	    shift
	    set XGAMMA=$1
	breaksw
	case -drmax:
	    shift
	    set DRMAX=$1
	breaksw
	default:
	    echo "Unknown option $1."
	    echo $USAGE
	    exit
	breaksw
    endsw
    if($# > 0) shift
end
echo $NSTEPS $XGAMMA $DRMAX > _tmp
cat _tmp $FNAME | $EXEC
rm _tmp
##

